<!DOCTYPE html>
<html lang="en">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<!-- Meta, title, CSS, favicons, etc. -->
		<meta charset="utf-8">
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<meta name="viewport" content="width=device-width, initial-scale=1">

		<title>添加仓库页面 </title>

		<!-- Bootstrap -->
		<link href="css/bootstrap.min.css" rel="stylesheet">
		<!-- Font Awesome -->
		<link href="css/font-awesome.min.css" rel="stylesheet">
		<!-- NProgress -->
		<!--<link href="css/nprogress.css" rel="stylesheet">-->

		<!-- Custom Theme Style -->
		<link href="css/custom.min.css" rel="stylesheet">

	</head>

	<body class="nav-md">
		<div class="container body">
			<div class="main_container">
				<div id="head">
						</div>

				<!-- top navigation -->
			
				<!-- /top navigation -->
				<!-- page content -->
				<div class="right_col" role="main">
					<div class="">
						<div class="page-title">
							<div class="title_left">
								<h3 style="color: green;">添加仓库</h3>
							</div>

							<div class="title_right">
								<div class="col-md-5 col-sm-5 col-xs-12 form-group pull-right top_search">

								</div>
							</div>
						</div>
						<div class="clearfix"></div>

						<div class="row">
							<div class="col-md-12 col-sm-12 col-xs-12">
								<div class="x_panel">
									<div class="x_title">

									</div>
									<div class="x_content">

										<form class="form-horizontal form-label-left" novalidate id="f">


											<div class="item form-group">
												<label class="control-label col-md-3 col-sm-3 col-xs-12" >仓库名 <span class="required">*</span>
												</label>
												<div class="col-md-6 col-sm-6 col-xs-12">
													<input id="depotname" class="form-control col-md-7 col-xs-12"  name="depotname" placeholder="请填写仓库名" required="required" type="text">
												</div><span class="name chickComment" style="color: red;font-size: large"></span>
											</div>


											<div class="item form-group">
												<label class="control-label col-md-3 col-sm-3 col-xs-12" >仓库区域 <span class="required">*</span>
												</label>
												<!--地区三级联动-->
												<div class=" col-xs-9" >
													<select  id="s_province" name="s_province"  style="padding: 6px 2px;" ></select>

													<select id="s_city" name="s_city"  style="padding: 6px 2px;"></select>

													<select id="s_county" name="s_county"  style="padding: 6px 2px;"></select>

													<input type="hidden" id="depotarea" name="depotarea" value=""/>
													<span class="cityC chickComment" style="color: red;font-size: large"></span>
												</div>
											</div>

											<div class="item form-group">
												<label class="control-label col-md-3 col-sm-3 col-xs-12" for="dAddress">仓库详细地址 <span class="required">*</span>
												</label>
												<div class="col-md-6 col-sm-6 col-xs-12">
													<textarea id="dAddress" required="required" name="dAddress" placeholder="请填写仓库详细地址" class="form-control col-md-7 col-xs-12"></textarea>
												</div><span class="addressC chickComment" style="color: red;font-size: large"></span>
											</div>
											<div class="item form-group">
												<label class="control-label col-md-3 col-sm-3 col-xs-12" for="dSize">仓库大小 <span class="required">*</span>
												</label>
												<div class="col-md-6 col-sm-6 col-xs-12">
													<input type="text" id="dSize" name="dSize" required="required" placeholder="请填写仓库大小" class="form-control col-md-7 col-xs-12" onkeyup="value=value.replace(/[^\d]/g,'')">
												</div><span class="dSize chickComment" style="color: red;font-size: large"></span>
											</div>
											<div class="item form-group">
												<label class="control-label col-md-3 col-sm-3 col-xs-12" for="dPersonid">仓库负责人 <span class="required">*</span>
												</label>
												<div class=" col-xs-9">
													<select id="dPersonid"  style="height: 30px;text-align: center"  name="dPersonid">
														<option value="">—请选择—</option>
													</select>
													<span class="dPersonid chickComment" style="color: red;font-size: large"></span>
												</div>
											</div>
											<div class="item form-group">
												<label class="control-label col-md-3 col-sm-3 col-xs-12" >负责人联系方式 <span class="required">*</span>
												</label>
												<div class="col-md-6 col-sm-6 col-xs-12">
													<input type="telephone" id="dPhone" name="dPhone" required="required" placeholder="请填写联系方式" class="form-control col-md-7 col-xs-12">
												</div><span class="aPhoneC chickComment" style="color: red;font-size: large"></span>
											</div>
											<div class="item form-group">
												<label class="control-label col-md-3 col-sm-3 col-xs-12" for="dCreatedate">仓库建立时间<span class="required">*</span>
												</label>
												<div class="col-md-6 col-sm-6 col-xs-12">
													<input type="date" id="dCreatedate" name="dCreatedate" required="required"  class="form-control col-md-7 col-xs-12">
												</div><span class="dCreatedate chickComment" style="color: red;font-size: large"></span>
											</div>
											
											<div class="ln_solid"></div>
											<div class="form-group">
												<div class="col-md-6 col-md-offset-3">
													<button id="send" type="button" class="btn btn-success">新增</button>
													<a href="javascript:;" class="btn btn-primary" onclick="window.history.back(-1)">返回</a>
												</div>
											</div>
										</form>
									</div>
								</div>
							</div>
						</div>
					</div>
				</div>
				<!-- /page content -->

				<!-- footer content -->
				<footer>
					<div class="pull-right">
						Gentelella - Bootstrap Admin Template by <a href="https://colorlib.com">Colorlib</a>
					</div>
					<div class="clearfix"></div>
				</footer>
				<!-- /footer content -->
			</div>
		</div>

		<!-- jQuery -->
		<script src="js/jquery.min.js"></script>
		<!-- Bootstrap -->
		<script src="js/bootstrap.min.js"></script>
		<!-- FastClick -->
		<script src="js/fastclick.js"></script>
		<!-- NProgress -->
		<script src="js/nprogress.js"></script>
		<!-- validator -->
		<script src="js/validator.js"></script>
		<script src="js/area.ui.js"></script>
		<!-- Custom Theme Scripts -->

		<!-- validator -->
		<script>
            var $token=window.sessionStorage.getItem('token');
				$(document).ready(function(){
					$("#head").load("head.html");

				});
                $.ajax({
                    type:"post",
                    xhrFields:{withCredentials:true},
                    url:"http://localhost:8081/depot/insert?token="+$token,
                    dataType:"json",
					success:function(data) {
                        $.each(data, function (i, user) {
                            $("#dPersonid").append("<option value='" + user.id + "'>" + user.username + "</option>");
                        });
                    },
					error:function () {
						alert("错误")
                    }
				});
            $("#send").click(function(){
                if($("#depotname").val()==""&&$.trim($("#depotname").val()).length==0){
                    $(".name").html("请填写仓库名字");
                    return false;
                }else if ($.trim($("#depotname").val()).length>10){
                    $(".name").html("仓库名字不能长于10");
                    return false;
				} else{
                    $(".name").html("");
                }
                if($("#depotarea").val()==""&&$.trim($("#depotarea").val()).length==0){
                    $(".cityC").html("请输入仓库所在区域");
                    return false;
                }else{
                    $(".cityC").html("");
                }
                if($("#dAddress").val()==""&&$.trim($("#dAddress").val()).length==0){
                    $(".addressC").html("请填写仓库详细地址");
                    return false;
                }else{
                    $(".addressC").html("");
                }
                if($("#dSize").val()==""&&$.trim($("#dSize").val()).length==0){
                    $(".dSize").html("请填写仓库大小");
                    return false;
                }else if ($("#dSize").val()>1000){
                    $(".dSize").html("仓库大小不能大于1000");
                    return false;
                } else{
                    $(".dSize").html("");
                }
                if($("#dPersonid").val()==null||$("#dPersonid").val().length==0){
                    $(".dPersonid").html("请输入仓库负责人");
                    return false;
                }else{
                    $(".dPersonid").html("");
                }

                if ($("#dPhone").val()!=""){
                    if(!(/^1(3|4|5|7|8)\d{9}$/.test($("#dPhone").val()))){
                        $(".aPhoneC").html("手机号格式有误，请填写正确手机号！");
                        return false;
                    }else{
                        $(".aPhoneC").html("");
                    }
                }else {
                    $(".aPhoneC").html("手机不能为空！");
                    return false;
                }
                if($("#dCreatedate").val()==""&&$.trim($("#dCreatedate").val()).length==0){
                    $(".dCreatedate").html("请输入仓库创建时间");
                    return false;
                }else{
                    $(".dCreatedate").html("");
                }
                $.ajax({
                    type:"post",
                    xhrFields:{withCredentials:true},
                    url:"http://localhost:8081/depot/add?token="+$token,
					data:$("#f").serialize(),
                    dataType:"json",
                    success:function (data) {
                        if (data.message="yes") {
                            alert("新增成功");
                            window.location.href="checkwarehouse.html";
                        }else{
                            alert("新增失败");
                        }
                    }

                })
            })
			// initialize the validator function
			validator.message.date = 'not a real date';

			// validate a field on "blur" event, a 'select' on 'change' event & a '.reuired' classed multifield on 'keyup':
			/*$('form')
				.on('blur', 'input[required], input.optional, select.required', validator.checkField)
				.on('change', 'select.required', validator.checkField)
				.on('keypress', 'input[required][pattern]', validator.keypress);

			$('.multi.required').on('keyup blur', 'input', function() {
				validator.checkField.apply($(this).siblings().last()[0]);
			});

			$('form').submit(function(e) {
				e.preventDefault();
				var submit = true;

				// evaluate the form using generic validaing
				if (!validator.checkAll($(this))) {
					submit = false;
				}

				if (submit)
					this.submit();

				return false;
			});*/
            //地区三级联动开始
            $(function(){
                $(document).area("s_province","s_city","s_county");//调用插件
                var str="";
                var str2="";

                $('#s_province').change(function(){
                    $('#s_province').children().each(function(){
                        if($(this).prop('selected')==true){
                            str="";
                            str=$(this).html();
                            $('#depotarea').val(str);
                            document.getElementById("dAddress").setAttribute("placeholder","如:"+str+"XX市XX区XX路X号");
                        }
                    });

                });
                $('#s_city').change(function(){
                    $('#s_city').children().each(function(){
                        if($(this).prop('selected')==true){
                            str2=$(this).html();
                            $('#depotarea').val(str+$(this).html());
                            document.getElementById("dAddress").setAttribute("placeholder","如:"+str+$(this).html()+"XX区XX路X号");
                        }
                    });

                });
                $('#s_county').change(function(){
                    $('#s_county').children().each(function(){
                        if($(this).prop('selected')==true){
                            $('#depotarea').val(str+str2+$(this).html());
                            document.getElementById("dAddress").setAttribute("placeholder","如:"+str+str2+$(this).html()+"XX路X号");
                        }
                    });


                });});

            //地区三级联动结束



		</script>
		<!-- /validator -->
	</body>
</html>
